package cc.xuanhaojituan.log4j.controller;

import cc.xuanhaojituan.log4j.domain.User;
import cc.xuanhaojituan.log4j.service.impl.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @author chenli
 * @create 2017-09-13
 */
@Controller
public class IndexController {
    private static final Logger log = LoggerFactory.getLogger(IndexController.class);
    @Autowired
    private UserServiceImpl userServiceImpl;

    @GetMapping("/index")
    public String index(){
        return "index";
    }

    @ResponseBody
    @GetMapping("insert")
    public String insert(){
        User user = new User();
        user.setUserName("chenli");
        user.setAge(20);
        user.setAddTime(new Date());
        userServiceImpl.insert(user);
        return "SUCCESS";
    }

    @ResponseBody
    @GetMapping("findList")
    public List<User> findList(){
        log.info("111");
        return userServiceImpl.findList();
    }
}